package updown.domain;

import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Title: ww.kaixin.downupservice.domain </p>
 * <p>Description:to-22-6-1: -  </p>
 *
 * @Author:jiangkaixin
 * @Date:2021/12/28
 * @Version: 1.0
 */
@Data
public class TaskWrapperMapperBean extends BaseEntity {

    private String startTime;
    private String endTime;
    // 总耗时
    private String totalSpend;
    // 任务编号
    private String taskId;
    // 是否成功
    private Boolean success;
    // JarInfo
    private String jarInfo;
    // ServerHostInfo
    private String serverHostInfo;
    // ServiceInfo
    private String serviceInfoJson;
    private String serviceName;
    private List<TaskInfoMapperBean> taskInfos = new ArrayList<>();
    // Jar包上传、服务替换
    private String taskType;

    public TaskWrapper convertToTaskWrapper() {
        TaskWrapper taskWrapper = TaskWrapper.builder()
                .startTime(this.startTime)
                .endTime(this.endTime)
                .totalSpend(this.totalSpend)
                .taskId(this.taskId)
                .success(this.success)
                .jarInfo(this.jarInfo)
                .serverHostInfo(this.serverHostInfo)
                .serviceInfoJson(this.serviceInfoJson)
                .serviceName(this.serviceName)
                .taskType(this.taskType)
                .build();
        if(!this.taskInfos.isEmpty()){
            for (TaskInfoMapperBean taskInfo : this.taskInfos) {
                TaskInfo info = new TaskInfo();
                BeanUtils.copyProperties(taskInfo,info);
                taskWrapper.getTaskInfos().add(info);
            }
        }
        return taskWrapper;
    }
}
